VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsParticle"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'====================================================================================
'clsParticle - A single particle (small floating sprite) on the level
'====================================================================================
Option Explicit

Public ParticleType As PM_PARTICLETYPE  'Which image / pattern this particle uses
Public Life As Long                     'How many frames it should last for
Public X As Single                      'X Position on level (Pixels)
Public Y As Single                      'Y Position on level (Pixels)
Public ID As String                     'Unique ID for this particle

Private OriginalX As Long               'The point the particle started at (X)
Private OriginalY As Long               'The point the particle started at (Y)

Private Progress As Long                'Number of frames elapsed so far
Private Splay As Single                 'Amount of spread for some particles
Private Force As Single                 'Amount of speed/force for some particles

'====================================================================================
'AssignProperties: A single way to setup the particle's properties
'====================================================================================
Public Function AssignProperties(ByVal pType As PM_PARTICLETYPE, ByVal pX As Long, ByVal pY As Long, ByVal LifeSpan As Long) As String
    Me.ParticleType = pType
    OriginalX = pX: OriginalY = pY
    Me.X = pX: Me.Y = pY
    Me.Life = LifeSpan
    
    'Create a unique ID for this particle
    Randomize
    Me.ID = ":" & Me.ParticleType & Me.X & Me.Y & Timer & Int(Rnd(1) * 10000)
    
    'Choose a random splay. The cookies need this for their direction
    Randomize
    Splay = (Rnd(1) * 2) - 1
    Force = Rnd(1) * 1
    
    'Move the particle ready for the first frame
    Move
    
    'Return the ParticleID to the caller
    AssignProperties = Me.ID
End Function

'====================================================================================
'Move: Move the particle in a certain behaviour
'====================================================================================
Public Function Move()
    Const SinWaveLength As Single = 0.1
    Const SinAmplitude As Long = 13
    
    Select Case ParticleType
        Case PM_PARTICLETYPE.PT_COOKIE1, PM_PARTICLETYPE.PT_COOKIE2
            'Cookies fall down
            Y = (Y - ((Force * 2) + 6)) + Progress
            X = X + (Splay * 2)
        
        Case PM_PARTICLETYPE.PT_X2
            Y = Range(OriginalY - (Progress * 2), OriginalY - 15, OriginalY)
        
        Case Else
            'Other particles float upward side to side
            Y = Y - (1 + (Force * 0.5))
            X = OriginalX + Sin((OriginalX + OriginalY - Y) * SinWaveLength) * (SinAmplitude + (Splay * 2))
    End Select
    
    Progress = Progress + 1
End Function

'=== END ============================================================================
'This work is licenced under the Creative Commons Attribution 2.5 License
